package io.renren.modules.jxgk.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.jxgk.entity.StudentAttendenceDetailsEntity;
import io.renren.modules.jxgk.service.StudentAttendenceDetailsService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.wuwenze.poi.ExcelKit;


@RestController
@RequestMapping("StudentAttendenceDetails/")
public class StudentAttendenceDetailsController {

    @Autowired
    StudentAttendenceDetailsService studentAttendenceDetailsService;

    @RequestMapping("Select")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<StudentAttendenceDetailsEntity> cse = studentAttendenceDetailsService.queryList(query);
        int total = studentAttendenceDetailsService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    @RequestMapping("getMyStudentAttendenceDetails")
    public R getMyStudentAttendenceDetails(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);
        List<StudentAttendenceDetailsEntity> cse = studentAttendenceDetailsService.getMyStudentAttendenceDetails(query);
        int total = studentAttendenceDetailsService.getMyStudentAttendenceDetailsTotal(query);

        PageUtils pageUtil = new PageUtils(cse, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    @RequestMapping("/export")
    public R export(HttpServletResponse response, @RequestParam Map<String,Object> map) {
        List<StudentAttendenceDetailsEntity> cse=null;
        try{
            ExcelKit.$Builder(StudentAttendenceDetailsEntity.class);

            cse=studentAttendenceDetailsService.queryList( map);
            ExcelKit.$Export(StudentAttendenceDetailsEntity.class, response).toExcel(cse, "学生考勤记录");
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return R.ok();
    }

}